import pyodbc

class DbProvider:
    cnxn = None
    driver = ''

    def __init__(self, server, username, passwd, database, driver='{ODBC Driver 11 for SQL Server}'):
        self.driver = driver
        self.cnxn = pyodbc.connect('DRIVER='+self.driver+';SERVER='+server+';PORT=1433;DATABASE='+database+';UID='+username+';PWD='+ passwd)

    def ExecuteQuerySql(self, sqlStr):
        cursor = self.cnxn.cursor()
        cursor.execute(sqlStr)
        return cursor

    def ExecuteNullQuery(self, sqlStr, parameters):
        cursor = self.cnxn.cursor()
        cursor.execute(sqlStr, parameters)
        cursor.commit()
        return True

    def ExecuteManyNullQuery(self, sqlStr, params):
        try:
            cursor = self.cnxn.cursor()
            cursor.executemany(sqlStr, params)
            cursor.commit()
            return True
        except:
            return False